import { createRouter, createWebHistory } from 'vue-router'

// import { useAccountStore } from '../stores/account.js'
import db from '../utils/localstorage.js'
import HomeNew from '../pages/homeNew/Home.vue'
import Airdrop from '../pages/airdrop/Airdrop.vue'
import LoginCallback from '../pages/LoginCallback.vue'
import GoogleLoginCallback from '../pages/GoogleLoginCallback.vue'
import NotFound from '../pages/NotFound.vue'

const routes = [
  {
    path: '/',
    redirect: '/laugh'
  },
  {
    path: '/home',
    redirect: '/laugh'
  },
  {
    path: '/laugh',
    component: HomeNew
  },
  {
    path: '/airdrop',
    component: Airdrop
  },
  {
    path: '/authorization',
    component: LoginCallback
  },
  {
    path: '/google-callback',
    component: GoogleLoginCallback
  },
  {
    path: '/404',
    component: NotFound
  },
  {
    path: '/:pathMatch(.*)*',
    redirect: '/404'
  }
]
const noLoginPages = [
  '/login'
]

export const router = createRouter({
  history: createWebHistory(`/${import.meta.env.VITE_BASE}`),
  routes
})

router.beforeEach(async (to, from) => {
  // const accountStore = useAccountStore()
  // await accountStore.getUser()

  // if (noLoginPages.indexOf(to.path) !== -1) {
  //   return true
  // } else {
  //   // const user = db.get('USER', null)
  //   const token = db.get('ACCESS_TOKEN', '')
  //   if (token) {
  //     return true
  //   } else if (
  //     to.path === '/login' ||
  //     to.path === '/laugh' ||
  //     to.path === '/airdrop' ||
  //     to.path === '/login-old' ||
  //     to.path === '/authorization'
  //   ) {
  //     return true
  //   } else {
  //     // 跳转登录页
  //     location.href = '/login'
  //   }
  // }

  return true
})